package cn.wanho.controller;

import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.service.CmsExamService;
import cn.wanho.service.ExamService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/exam")
public class ExamController {
    @Resource
    private ExamService examService;

    /**
     * 验证当前学生有没有未进行的考试
     * @return 111111
     *
     */
    @GetMapping("/testCheck")
    public ResultVO testCheck(Integer userId) throws JsonProcessingException {
//        return ResultVO.success(ResultEnum.TEST_EXIST_SUCCESS.getResCode(), ResultEnum.TEST_START_SUCCESS.getResMsg(),"汪永成");
        return examService.testCheck(userId);
    }

    /**
     * 开始考试，展示试卷
     */
    @GetMapping("/testing")
    public ResultVO testing(Integer paperId,Integer id){
        return examService.testing(paperId,id);
    }

    /**
     * 保存当前答题（redis存储）
     * @param questionId
     * @param answerContent
     * @param paperId
     * @return
     */
    @PostMapping("/saveAnswer")
    public ResultVO saveExam(String questionId,String answerContent,String paperId,Integer id) throws IllegalAccessException {
        return examService.saveExam2(questionId,answerContent,paperId,id);
    }

    /**
     * 考试结束提交试卷
     * @param paperId
     * @param userId
     * @return
     */
    @PostMapping("/commit")
    public ResultVO commit(Integer userId,String paperId){
        return examService.commit(userId,paperId);
    }

    /**
     * 展示试题卷（只包含题目）
     */
    @GetMapping("/showpaper")
    public ResultVO showPaper(Integer paperId,Integer sort,Integer studentId) throws NoSuchFieldException, IllegalAccessException {
        return examService.showPaper(paperId,sort,studentId);
    }
}
